﻿namespace StudentsWithLINQ
{
    using System;
    using System.Linq;
    using ExtensionMethods;

    public class MainStudents
    {
        //// 1.2.16.03. Write a method that from a given array of students finds all students whose first name is before its
        //// last name alphabetically. Use LINQ query operators.
        //// 1.2.16.04. Write a LINQ query that finds the first name and last name of all students with age between 18 and 24.
        //// 1.2.16.05. Using the extension methods OrderBy() and ThenBy() with lambda expressions sort the students by
        //// first name and last name in descending order. Rewrite the same with LINQ.

        private static void Main()
        {
            var sample = new Student[]
            {
                new Student("Simeon", "Veliki", 28),
                new Student("Vasil", "Kunchev", 25),
                new Student("Ivan", "Ivanov", 19),
                new Student("Georgi", "Georgiev", 24),
                new Student("Petur", "Petrov", 18)
            };

            // Student[] sample2 = new Student[] // The property or indexer 'StudentsWithLINQ.Student.FirstName' cannot be used in this context because the set accessor is inaccessible
               
            // {
            //     new Student
            //     {
            //         FirstName = "Asdf",
            //         LastName = "Fdsa",
            //         Age = 22
            //     }
            // };

            var studentsWithFirstNameBeforeLastNameAlphabetically = sample.Where(x => x.FirstName[0] < x.LastName[0]);
            studentsWithFirstNameBeforeLastNameAlphabetically.PrintCollection();

            MainExtensionMethods.Separator();

            var studentsFilteredByAgeAndSelectedSomeProps = sample.Where(x => x.Age > 18 && x.Age < 24)
                .Select(x => new
                {
                    fName = x.FirstName,
                    lName = x.LastName
                });

            studentsFilteredByAgeAndSelectedSomeProps.PrintCollection();

            MainExtensionMethods.Separator();

            var sortedStudentsByNamesLambda = sample.OrderByDescending(x => x.FirstName).ThenByDescending(x => x.LastName);
            sortedStudentsByNamesLambda.PrintCollection();

            MainExtensionMethods.Separator();

            var sortedStudentsByNamesLINQ =
                from x in sample
                orderby x.FirstName descending, x.LastName descending
                select x;

            sortedStudentsByNamesLINQ.PrintCollection();
        }
    }
}